package com.wclass.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.wclass.entity.PostsLike;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 帖子点赞记录 Mapper 接口
 * </p>
 *
 * @author SEN
 * @since 2018-12-27
 */
public interface PostsLikeMapper extends BaseMapper<PostsLike> {

    @Override
    @Select("SELECT COUNT(info.id) from posts_like info left join posts_info posts on info.posts_id = posts.id where 1=1 ${ew.sqlSegment}")
    Integer selectCount(@Param("ew") Wrapper<PostsLike> wrapper);


    /**
     * 获取未读点赞分页
     * @param page
     * @param userId
     * @return
     */
    @Select("select info.*,baseAppUser.nick_name,baseAppUser.picture_address from posts_like info " +
            "left join base_app_user as baseAppUser on info.user_id = baseAppUser.id " +
            "where info.state = 0 and " +
            "(info.reply_id in (select id from posts_reply where user_id = #{userId}) or info.posts_id in (select id from posts_info where user_id = #{userId})) " +
            "order by info.is_new asc,info.crt_time desc")
    List<PostsLike> selectUnreadPostsLikePage(Pagination page, @Param("userId") Long userId);

}
